<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="box-card">
        <el-tabs v-model="activeName">
          <el-tab-pane label="登陆账户设置" name="first">
            <el-form style="margin-top:50px">
              <el-form-item label="姓名:" label-width="450px">
                <el-input v-model="username" style="width:400px" />
              </el-form-item>
              <el-form-item label="密码:" label-width="450px">
                <el-input v-model="newPassword" type="password" style="width:400px" />
              </el-form-item>
              <el-row type="flex" justify="center">
                <el-button @click="update">更新</el-button>
                <el-button @click="$router.back()">取消</el-button>
              </el-row>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情" name="second">
            <component :is="personalDetail" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息" name="third">
            <component :is="jobInfo" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import personalDetail from '../components/personalDetail'
import jobInfo from '../components/jobInfo'
import { getEmployeeInfo, saveEmployeeInfo } from '@/api/employees'
export default {
  components: {
    personalDetail
  },
  data() {
    return {
      personalDetail: personalDetail,
      jobInfo: jobInfo,
      id: this.$route.params.id,
      activeName: 'first',
      username: '',
      password: '',
      newPassword: ''

    }
  },
  created() {
    this.getEmployeeInfo()
  },
  methods: {
    async getEmployeeInfo() {
      console.log(this.id)
      const res = await getEmployeeInfo(this.id)
      console.log(res)
      this.username = res.username
    },
    async update() {
      const data = {
        username: this.username,
        password: this.newPassword
      }
      const res = await saveEmployeeInfo(this.id, data)
      console.log(res)
    }
  }
}
</script>

<style>

</style>
